package cn.zn.modules.invoice.controller;

import cn.zn.framework.common.exception.RRException;
import cn.zn.modules.invoice.inter.InvoiceRecordInfoInter;
import cn.zn.modules.pz.inter.PzInter;
import cn.zn.modules.pz.inter.vo.PzForInvoiceVO;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 发票信息
 *
 * @author zn
 * @email zhunahao@qq.com
 * @date 2020-04-08 22:07:19
 */
@Controller
@RequestMapping("web/invoice/invoicedetail")
public class InvoiceDetailMvcController implements ApplicationContextAware {

    @RequestMapping("invoiceList")
    public void invoiceList(ModelMap modelMap, String recordCode) {
        modelMap.put("recordCode", recordCode);
    }

    @RequestMapping("invoiceEdit")
    public void invoiceEdit(ModelMap modelMap, String recordCode) throws Exception {
        if (pzInter != null) {
            PzForInvoiceVO pzForInvoiceVO = pzInter.findPz(recordCode);
            if (pzForInvoiceVO == null) {
                throw new Exception(String.format("单据不存在：%s", recordCode));
            }
            modelMap.put("recordInfo", pzForInvoiceVO);
            modelMap.put("showRecord", true);
        } else {
            modelMap.put("showRecord", false);
        }
        modelMap.put("recordCode", recordCode);
    }

    /**
     * 凭证接口
     */
    private PzInter pzInter;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (applicationContext.containsBean("pzInter")) {
            Object obj = applicationContext.getBean("pzInter");
            if (obj instanceof PzInter) {
                pzInter = (PzInter) applicationContext.getBean("pzInter");
            }
        }

    }
}
